//
//  SignedInteger+Additions.swift
//  MGExtensionsKit
//
//  Created by Max on 2020/4/15.
//

import Foundation

extension SignedInteger {
    /// 将以分为单位的价格转换为以元为单位的字符串格式
    /// 无小数位返回整数，有小数位有几位返回几位，但不会超过两位
    public var priceString: String {
        var priceString = "\(self/100)"
        var cent = self % 100
        if cent > 0 {
            if cent < 10 {
                priceString += ".0\(cent)"
            }else {
                if cent % 10 == 0 {
                    cent = cent/10
                }
                priceString += ".\(cent)"
            }
        }
        return priceString
    }
}
